package com.huang.we_chart.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huang.we_chart.VO.StudentVO;
import com.huang.we_chart.entity.Department;
import com.huang.we_chart.entity.Student;
import com.huang.we_chart.service.DepartmentService;
import com.huang.we_chart.service.StudentService;
import com.huang.we_chart.util.Result;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * (Student)表控制层
 *
 * @author HuangShen
 * @since 2020-11-29 10:11:37
 */
@RestController
@RequestMapping("student")
@CrossOrigin
public class StudentController {
    @Resource
    private StudentService studentService;
    @Resource
    private DepartmentService departmentService;
@GetMapping("/getStudentById")
    public Result getStudentById(String id) {
    Student student = studentService.getOne(new QueryWrapper<Student>().eq("student_id", id));
    Department department = departmentService.getOne(new QueryWrapper<Department>().eq("department_id", student.getDepartmentId()));

    StudentVO studentVO = new StudentVO();
    studentVO.setDepartnent(department.getDepartmentName());
    studentVO.setId(student.getStudentId());
    studentVO.setName(student.getStudentName());
    studentVO.setNickName(student.getNickName());

    return new Result("200","success",studentVO);

    }


}